package com.xjl.example.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by xiaojinlu1990@163.com on 2019/12/1.
 * 线程池的核心方法
 * 1 execute  调用线程功能执行
 * 2 submit  调用线程执行有返回值
 * 3 shoutDown  等任务执行完在停止
 * 4 shoutDownNew 立即结束执行
 *
 */
@Slf4j
public class ThreadPoolExample3 {

    public static void main(String[] args) {
        ScheduledExecutorService service = Executors.newScheduledThreadPool(5);
//        service.schedule(new Runnable() {
//            @Override
//            public void run() {
//                log.info(" schedule running");
//            }
//        },3, TimeUnit.SECONDS);
        service.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                log.info(" schedule running");
            }
        },1,3, TimeUnit.SECONDS);
//        service.shutdown();
    }
}
